import { reactive, onMounted, ref, nextTick } from 'vue'
import useInstance from '@/hooks/useInstance';
import { menuAddApi,menuRemoveApi } from '@/api/menu/menu'
import { RolePageParams, RoleTable } from '@/api/role/roleModel'
import { EditType } from '@/type/BaseEnum'
export default function menuEdit(getMenuList){
  const { global, proxy } = useInstance()
  let fileType=ref()
  const RefMenuAddEdit = ref<{ show: (type: string, row?: any) => void }>()
  const addBtn = (fileType) => {
    fileType.value=fileType
    
    RefMenuAddEdit?.value?.show(EditType.ADD)
  }
  const editBtn = (row) => {
    RefMenuAddEdit?.value?.show(EditType.EDIT, row)
  }
    const save = async (row) => {
      console.log(row,'save');
      
    let res
    if (row?.id) {
      // res = await roleUpdateApi(row)
    } else {
      res = await menuAddApi(row)
    }
    if (res.code === 200 && row?.id) {
      global.$message({ message: '编辑成功', type: 'success' })
      getMenuList()
    } else {
      global.$message({ message: '新增成功', type: 'success' })
      getMenuList()
    }
  }
  const deleteBtns = async (id: number | string) => {
    const confirm = await global.$myconfirm('确定删除该部门嘛?')
    if (confirm) {
      const res = await menuRemoveApi({ id })
      if (res.code === 200) {
        global.$message({ message: '删除成功', type: 'success' })
          getMenuList()
      }
    } else {
      global.$message({ message: "已取消删除", type: 'warning' })
    }
  }
  return {
    addBtn,editBtn,save,deleteBtns,RefMenuAddEdit,fileType
  }
}